TimerOut
 
 
 Bean TimerOut
 
Flip-flop output 1:1

Typical usage of the bean in user's code.

Typical Usage:

Required bean name is "TO1".
There are the following three typical usage modes:

(1)
The easiest usage of the bean is a simple output signal generator. There is not method required in this simple mode. The bean initializes the timer, which produces the output signal with 50% duty.

Note: In this case it is recommended to turn off all the methods of the bean.

(2)
The bean may be at the same time used as a simple periodic event generator - event OnRising or OnFalling may be used. Usually it's recommended to use only one of these events.

 EVENTS.C

int event_cntr = 0;

void TO1_OnFalling()
{
  ++event_cntr; /* increment event counter */
}

(3)
Advanced methods of the bean allows to change period of the event in runtime. It is possible to select a period from the predefined list using SetPeriodMode method or to set a value from the interval using SetPeriod and SetFreq methods (please refer to Bean Timing Dialog).
In the following example the output signal period is switched after each 255-th invocation of the event handler. The period mode is changed sequentially from three predefined values.

 EVENTS.C

int rpt_cntr = 255, mode = 0;

void TO1_OnFalling(void)
{

  if( --rpt_cntr==0 ) {  // If the event was generated 255times
    if( ++mode==3 ) mode = 0; // Select next mode of the period
    TO1_SetPeriodMode( mode ); // Set new period mode
    rpt_cntr = 255; // Set repeat counter
  }
}

(4)
Bean initial level of the output signal may be changed using methods SetValue and ClrValue. These methods may used only if the bean is disabled.

 MAIN.C

void main(void)
{
  /* output signal synchronization */
  TO1_Disable();  /* disable the bean */
  TO1_ClrValue(); /* set output level to LOW */
  TO1_Enable();   /* enable the bean */
}

For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.


Processor ExpertTM and Embedded BeansTM are registered trademarks of UNIS, Ltd.
©1997-2005, UNIS, Ltd.